package com.lk.springboot.utils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lk
 * @date 2020/1/19 0019 11:03
 */
public class RandomUtil {

    /**
     * 游戏前获得随机碎片中的 稀有度控制  (获取几个稀有度) [ 游戏随机 ]
     *
     * @param n
     * @return
     */
    public List randomGetRares(int n) {
        String[] rares = {"A", "B", "C", "D"};
        int index = 3;
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int pr = (int) (Math.random() * 100);
            if (pr < 5)
                index = 0;
            else if (pr >= 5 && pr < 20)
                index = 1;
            else if (pr >= 20 && pr < 50)
                index = 2;
            else
                index = 3;
            String rare = rares[index];
            arrayList.add(rare);
        }
        return arrayList;
    }

    /**
     * 随机p_id(均匀随机)
     *
     * @param max
     * @param min
     * @param n
     * @return
     */
    public ArrayList randomGetPid(int max, int min, int n) {// [min,max]表示要产生随机数的范围
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int id = (int) (Math.random() * (max - min + 1)) + min;
            String p_id = "p" + id;
            arrayList.add(p_id);
        }
        return arrayList;
    }

    /**
     * 积分兑换中心  魔法市场
     *
     * @param choice
     * @param n
     * @return
     */
    public ArrayList scoreCenterRandomGetRares(int choice, int n) {
        String[] rares = {"A", "B", "C", "D"};
        int index = 3;
        ArrayList<String> arrayList = new ArrayList<>();
        if (choice == 0) {//积分兑换中心
            for (int i = 0; i < n; i++) {
                int pr = (int) (Math.random() * 100);
                if (pr < 15)
                    index = 0;
                else if (pr >= 15 && pr < 35)
                    index = 1;
                else if (pr >= 35 && pr < 55)
                    index = 2;
                else
                    index = 3;
                String rare = rares[index];
                arrayList.add(rare);
            }
        } else {//魔法市场
            for (int i = 0; i < n; i++) {
                int pr = (int) (Math.random() * 100);
                if (pr < 20)
                    index = 0;
                else if (pr >= 20 && pr < 45)
                    index = 1;
                else if (pr >= 45 && pr < 65)
                    index = 2;
                else
                    index = 3;
                String rare = rares[index];
                arrayList.add(rare);
            }
        }

        return arrayList;
    }

    /**
     * 兑换中心的 稀有度控制  (获取几个稀有度) [ 兑换中心抽奖随机 ]
     *
     * @param n
     * @return
     */
    public List CenterRandomGetRares(int n) {
        String[] rares = {"A", "B", "C", "D"};
        int index = 3;
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int pr = (int) (Math.random() * 100);
            if (pr < 3)
                index = 0;
            else if (pr >= 3 && pr < 10)
                index = 1;
            else if (pr >= 10 && pr < 20)
                index = 2;
            else
                index = 3;
            String rare = rares[index];
            arrayList.add(rare);
        }
        return arrayList;
    }

    /**
     * 魔法市场抽奖随机，获取道具
     *
     * @param max
     * @param min
     * @return
     */
    public int MagicRandomGetProps(int max, int min) {
        int props_id = (int) (Math.random() * (max - min + 1)) + min;
        return props_id;
    }

    /**
     * 完成任务，领取随机拼图奖励
     *
     * @param n
     * @return
     */
    public List taskRandomGetRares(int n) {
        String[] rares = {"A", "B", "C", "D"};
        int index = 3;
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int pr = (int) (Math.random() * 100);
            if (pr < 2)
                index = 0;
            else if (pr >= 2 && pr < 5)
                index = 1;
            else if (pr >= 5 && pr < 13)
                index = 2;
            else
                index = 3;
            String rare = rares[index];
            arrayList.add(rare);
        }
        return arrayList;
    }

    /**
     *随机选择是 实物奖励 还是 拼图奖励
     */
    public int randomGetAwardType(int max, int min) {// [min,max]表示要产生随机数的范围
        return  (int) (Math.random() * (max - min + 1)) + min;
    }

}
